package org.dey.controller;


import org.dey.entity.Result;
import org.dey.pojo.*;
import org.dey.service.VisitDiaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author deyran
 * @classname
 * @see VisitDiaryController
 */
@RestController
public class VisitDiaryController {

    @Autowired
    VisitDiaryService visitdiaryService;

    //    打开用户管理页面显示数据 @RequestParam /{pageno}/{pagesize} @PathVariable  @PathVariable
    //@RequestParam(value = "pagecurrent",defaultValue = "1")   @RequestParam(value = "pagesize",defaultValue = "5")
    @PostMapping("visitdiary.action/{pageNum}/{pagesize}")
    public PageVo<VisitDiary> visitdiarylist(@RequestBody VisitDiary visitdiary,@PathVariable int pageNum,@PathVariable int pagesize){
        System.out.println("pagecurrent——pagesize"+pageNum+"——"+pagesize);
        PageVo<VisitDiary> visitdiarys = visitdiaryService.queryvisitdiary(visitdiary, pageNum, pagesize);
        return visitdiarys;
    }

    //添加
    @PostMapping("visitdiary.action")
    public Result addvisitdiary(@RequestBody VisitDiary visitdiary){

        Result insertvisitdiary = visitdiaryService.insertvisitdiary(visitdiary);

        return insertvisitdiary;
    }

    //删除
    @DeleteMapping("visitdiary.action/{id}")
    public Result delvisitdiarybyid(@PathVariable int id){

        Result delvisitdiary = visitdiaryService.delvisitdiary(id);

        return delvisitdiary;
    }

    //修改先根据id查到该数据
    @GetMapping("visitdiary.action/{id}")
    public VisitDiary queryvisitdiarybyid(@PathVariable Integer id){

        VisitDiary queryvisitdiarybyid = visitdiaryService.queryvisitdiarybyid(id);
        System.out.println("Controller——queryvisitdiarybyid——"+queryvisitdiarybyid);
        return queryvisitdiarybyid;
    }

    //根据id修改
    @PutMapping("visitdiary.action")
    public Result updatevisitdiarybyid(@RequestBody VisitDiary visitdiary){

        Result updatevisitdiarybyid = visitdiaryService.updatevisitdiarybyid(visitdiary);

        return updatevisitdiarybyid;
    }

    @GetMapping("queryusers.action")
    public List<User> getUsers(){
        List<User> userRole = visitdiaryService.getUserRole();
        return userRole;
    }


    @GetMapping("querymembersname.action")
    public List<RenQunFenLei> getMembername(){
        List<RenQunFenLei> members = visitdiaryService.getmemberName();
        return members;
    }

}
